from apps.education.section.baseViews import *


class SectionViewSet(BaseSectionViewSet):

    def get_queryset(self):
        params = getRequestParams(self.request)
        _list = SectionDao().findAll()
        return _list
    
    # 获取章节树
    @action(methods=['post'], detail=False)
    def getSectionTree(self, request):
        params = getRequestParams(self.request)
        _courseId = params.get('courseId')
        if not _courseId:
            return Response(response_message('courseId参数必填'))
        _list = SectionDao().findAll().filter(course__id=_courseId).order_by('sort', 'id')
        tree = SectionDao().build_tree(SectionModelSerializer(_list, many=True).data)
        return Response(response_success(tree))
